﻿using System.Data;
using System.Data.SqlClient;
using IDAL;
using Model;

namespace DAL
{
    public class ProductSNState : BaseRepository<ProductSNStateInfo>, IProductSNState
    {
        private const string PARM_TEST_PRODUCTSN = "@ProductSN";

        #region 数据检索部分
        public ProductSNStateInfo ProductSN_IsDebug(string productSN)
        {
            SqlParameter parm = BuildParameter(productSN);
            return ExcuteSqlToGetEntity("ProductSN_IsDebug", parm);
        }

        public ProductSNStateInfo ProductSN_IsPIM(string productSN)
        {
            SqlParameter parm = BuildParameter(productSN);
            return ExcuteSqlToGetEntity("ProductSN_IsPIM", parm);
        }

        public ProductSNStateInfo ProductSN_IsTest(string productSN)
        {
            SqlParameter parm = BuildParameter(productSN);
            return ExcuteSqlToGetEntity("ProductSN_IsTest", parm);
        }

        public ProductSNStateInfo ProductSN_IsPackage(string productSN)
        {
            //Create a parameter    
            SqlParameter parm = BuildParameter(productSN);
            return ExcuteSqlToGetEntity("ProductSN_IsPackage", parm);
        }
        #endregion

        private SqlParameter BuildParameter(string productSN)
        {
            SqlParameter parm = GetParameter();
            //Bind the parameter
            parm.Value = productSN;
            return parm;
        }

        #region 重写基类部分
        //-------------------------------------重写超类基础操作---------------------------------------------------------

        public override ProductSNStateInfo GetEntityRecord(SqlDataReader rdr)
        {
            ProductSNStateInfo pro = new ProductSNStateInfo(rdr.GetValue(0).ToString(), rdr.GetDateTime(1), rdr.GetValue(2).ToString());
            return pro;
        }

        public override ProductSNStateInfo GetEntityRecord()
        {
            ProductSNStateInfo pro = new ProductSNStateInfo();
            return pro;
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_TEST_PRODUCTSN, SqlDbType.NVarChar, 50);
            return Parm;
        }
        #endregion
    }
}
